package com.spring.service.blog.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.spring.web.formbean.blog.BlogForm;
import com.spring.bean.blog.Blog;
import com.spring.dao.blog.BlogDao;
import com.spring.service.blog.BlogService;
import com.spring.bean.page.Page;
import com.spring.bean.page.PageView;
import com.spring.service.ServiceSupport;
import com.spring.exception.ServiceException;

@Service
@Transactional
public class BlogServiceImpl extends ServiceSupport implements BlogService {

	@Autowired
	private BlogDao blogDao;

	/** insert */
	public boolean insert(BlogForm blogForm) throws ServiceException {
		try{
			Blog blog = formToEntity(Blog.class, blogForm);
			return blogDao.insert(blog);
		} catch (Exception e) {
			throw new ServiceException("Blog --- insert error", e);
		}
	}

	/** update */
	public boolean update(BlogForm blogForm) throws ServiceException {
		try{
			Blog blog = formToEntity(Blog.class, blogForm);
			return blogDao.update(blog);
		} catch (Exception e) {
			throw new ServiceException("Blog --- update error", e);
		}
	}

	/** delete */
	public boolean delete(Integer id) throws ServiceException {
		try{
			return blogDao.delete(id);
		} catch (Exception e) {
			throw new ServiceException("Blog --- delete error", e);
		}
	}

	/** getById */
	public Blog getById(Integer id) throws ServiceException {
		try{
			return blogDao.getById(id);
		} catch (Exception e) {
			throw new ServiceException("Blog --- query by id error", e);
		}
	}

	/** queryForList */
	public List<Blog> queryForList() throws ServiceException {
		try{
			return blogDao.queryForList();
		} catch (Exception e) {
			throw new ServiceException("Blog --- query list error", e);
		}
	}

	/** queryForPage */
	public PageView<Blog> queryForPage(Page page) throws ServiceException {
		try{
			return blogDao.queryForPage(page);
		} catch (Exception e) {
			throw new ServiceException("Blog ---query page error", e);
		}
	}
}